package renders

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

// LoadHTML 配置路由信息
func LoadHTML(r *gin.Engine) {
	/*
	* 注意：
	* html顶部的`{{define "loadhtml/posts.html"}}`是渲染的时候的c.HTML的第二个参数
	* LoadHTMLGlob读取的html必须含有顶部信息
	 */
	r.LoadHTMLGlob("templates/**/*") // 多个
	//r.LoadHTMLFiles("templates/posts/index.html","templates/users/index.html")// 单个文件

	// 简单的路由组: LoadHTML
	load := r.Group("/load-html")
	{
		load.GET("/posts", func(c *gin.Context) {
			c.HTML(http.StatusOK, "loadhtml/posts.html", gin.H{
				"title":   "posts",
				"message": "欢迎posts访问！",
			})
		})
		load.GET("users", func(c *gin.Context) {
			c.HTML(http.StatusOK, "loadhtml/users.html", gin.H{
				"title":   "users",
				"message": "欢迎users访问！",
			})
		})
	}
}
